package com.data.modules.online.config.executor;

import freemarker.template.Configuration;
import java.io.StringWriter;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FreemarkerHelper {

    private static final Logger logger = LoggerFactory.getLogger(FreemarkerHelper.class);

    private static Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);

    static {
        configuration.setNumberFormat("0.#####################");
        configuration.setClassForTemplateLoading(FreemarkerHelper.class, "/");
    }

    public static String getStringWriter(String str, String str2, Map<String, Object> map) {
        try {
            StringWriter stringWriter = new StringWriter();
            configuration.getTemplate(str, str2).process(map, stringWriter);
            return stringWriter.toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return e.toString();
        }
    }

    public static String getStringWriterUtf(String str, Map<String, Object> map) {
        return getStringWriter(str, "utf-8", map);
    }
}
